/*
 * 作者：姚俊
 * 功能：项目的高级搜索的action
 * 日期：2015-06-26
 */
package admin.action.superSearch;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import admin.action.fruits.Constant;
import admin.service.fruits.ProjectService;

import teacher.bean.Project;
import tools.StringDate;

public class ProjectSuperAction {
	
	private List<Project> projects;
	private Project project;
	private int direction;
	//当前页
	private int currentPage;
	//最后一页
	private int endPage;
	private int counts;
	private int flag;
	private int code;
	

	//排序的属性
	private String level;
	private String kind;
	private String class_;
	private String finishDate;
	
	public List<Project> getProjects() {
		return projects;
	}


	public void setProjects(List<Project> projects){
		this.projects = projects;
	}


	public Project getProject() {
		return project;
	}


	public void setProject(Project project) {
		this.project = project;
	}


	public int getDirection() {
		return direction;
	}


	public void setDirection(int direction) {
		this.direction = direction;
	}


	public int getCurrentPage() {
		return currentPage;
	}


	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}


	public int getEndPage() {
		return endPage;
	}


	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}


	public int getCounts() {
		return counts;
	}


	public void setCounts(int counts) {
		this.counts = counts;
	}


	public int getFlag() {
		return flag;
	}


	public void setFlag(int flag) {
		this.flag = flag;
	}


	public int getCode() {
		return code;
	}


	public void setCode(int code) {
		this.code = code;
	}
	

	public String getLevel() {
		return level;
	}


	public void setLevel(String level) {
		this.level = level;
	}


	public String getKind() {
		return kind;
	}


	public void setKind(String kind) {
		this.kind = kind;
	}


	public String getClass_() {
		return class_;
	}


	public void setClass_(String class_) {
		this.class_ = class_;
	}


	public String getFinishDate() {
		return finishDate;
	}


	public void setFinishDate(String finishDate) {
		this.finishDate = finishDate;
	}


	public String execute()
	{
		//System.out.println(getClass_());
	//	System.out.println(getDate());
		this.setFlag(4);
		
		
		if(this.getProject()!=null)
		{
			if(this.getProject().getName()==null||this.getProject().getName().equals(""))
				this.getProject().setName(null);
			else
			{
				if(this.getCode()!=1)
				{
					try {
						this.getProject().setName(new String(this.getProject().getName().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
			if(this.getProject().getSource()==null||this.getProject().getSource().equals(""))
				this.getProject().setSource(null);
			else
			{
				if(this.getCode()!=1)
				{
					try {
						this.getProject().setSource(new String(this.getProject().getSource().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
			if(this.getProject().getLeader()==null||this.getProject().getLeader().equals(""))
				this.getProject().setLeader(null);
			else
			{
				if(this.getCode()!=1)
				{
					try {
						this.getProject().setLeader(new String(this.getProject().getLeader().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
			if(this.getProject().getOthers()==null||this.getProject().getOthers().equals(""))
				this.getProject().setOthers(null);
			else
			{
				if(this.getCode()!=1)
				{
					try {
						this.getProject().setOthers(new String(this.getProject().getOthers().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
			if(this.getProject().getNumber()==null||this.getProject().getNumber().equals(""))
				this.getProject().setNumber(null);
			else
			{
				if(this.getCode()!=1)
				{
					try {
						this.getProject().setNumber(new String(this.getProject().getNumber().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
			if(this.getProject().getBeginDate()!=null)
				this.getProject().setBeginDate(
						StringDate.StringToDate(
								StringDate.DateToString(
										this.getProject().getBeginDate())));
			if(this.getProject().getFinishDate()!=null)
				this.getProject().setFinishDate(
						StringDate.StringToDate(
								StringDate.DateToString(
										this.getProject().getFinishDate())));
			

		/*	System.out.println(this.getProject().getName());
			System.out.println(this.getProject().getBeginDate());
			System.out.println(this.getProject().getOthers());
			System.out.println(this.getProject().getLeader());
			System.out.println(this.getProject().getLowDepartment());
			System.out.println(this.getProject().getLevel());
			System.out.println(this.getProject().getArriveFunds());
			System.out.println(this.getProject().getSource());
			System.out.println("方向为:"+this.getDirection());
			System.out.println(this.getProject().getClass_());
			System.out.println(this.getProject().getFunds());
			System.out.println(this.getProject().getState());
			System.out.println("横向和纵向为:"+this.getProject().getKind());
			System.out.println(this.getProject().getProgress());
			System.out.println(this.getProject().getFinishDate());
			System.out.println(this.getProject().getLowDepartment());
			System.out.println(this.getProject().getTeaId());
			System.out.println(this.getRiqi());
			System.out.println(this.getDengji());*/

			
		}
		
		List<String> orders=new ArrayList<String>();
		
		/**
		 * @author 贺智远
		 */
		{
				
			
				if(this.getLevel()!=null&&!(this.getLevel().equals("")))
					{
						//System.out.println("等级"+this.getLevel());
						orders.add(this.getLevel());
					}
				if(this.getKind()!=null&&!(this.getKind().equals("")))
					{
					 // System.out.println("种类"+this.getKind());
						orders.add(this.getKind());
					}
				//System.out.println("kind的值为:"+this.getKind());
				if(this.getClass_()!=null&&!(this.getClass_().equals("")))
					{
				  //	System.out.println("类型"+this.getClass_());
						orders.add(this.getClass_());
					}
				
				
				if(this.getFinishDate()!=null&&!(this.getFinishDate().equals("")))
					{
					//System.out.println("日期"+this.getFinishDate());
						orders.add(this.getFinishDate());
					}
				//System.out.println("贺贺");
				//System.out.println(orders.size());
		}
	
	
	
		//System.out.println("order的尺寸为:"+orders.size());
		//当前页为零的时候，把当前页变成1
		if(this.getCurrentPage()==0)
			this.setCurrentPage(1);
		
		int add=0;
		//最后一页
		if(new ProjectService().getProjectCountByDirection(
				this.getProject(),this.getDirection(),Constant.state)%Constant.pageSize!=0)
		{
			add=1;
		}

		this.setEndPage(
				new ProjectService().getProjectCountByDirection(
						this.getProject(),this.getDirection(),Constant.state)/Constant.pageSize+add);
		this.setCounts(new ProjectService().getProjectCountByDirection(
				this.getProject(), this.getDirection(),Constant.state));
		System.out.println("数量为:"+this.getCounts());
		this.setProjects(
		new ProjectService().getSegregateProjectByDirection(
				this.getProject(),this.getDirection(),(this.getCurrentPage()-1)*Constant.pageSize+1,Constant.pageSize,Constant.state,orders));
		return "succ";
	}
		
}
